//
//  MyViewController.m
//  UI_元旦豆瓣半完整版
//
//  Created by dllo on 15/12/31.
//  Copyright © 2015年 lanou3g. All rights reserved.
//

#import "MyViewController.h"
#import "LandViewController.h"
#import "ActivityCllectViewController.h"
#import "MovieCllectViewController.h"
#import "MyDataBaseHandle.h"
#import "SDImageCache.h"


#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height

@interface MyViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) UITableView *tableView;

@end

@implementation MyViewController

- (void)dealloc {
    [_tableView release];
    [super dealloc];
}
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationItem.title = @"我的";
    self.navigationController.navigationBar.barTintColor = [UIColor purpleColor];
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"登陆" style:UIBarButtonItemStylePlain target:self action:@selector(itemAction:)];
    self.navigationItem.rightBarButtonItem = item;
    

    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) style:UITableViewStylePlain];
    [self.view addSubview:_tableView];
    [_tableView release];
    
    _tableView.dataSource = self;
    _tableView.delegate = self;
    
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    
    
}

- (void)item2Action:(UIBarButtonItem *)item {
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"注销" message:@"确定注销?" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"登陆" style:UIBarButtonItemStylePlain target:self action:@selector(itemAction:)];
        self.navigationItem.rightBarButtonItem = item;
    }];
    UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDestructive handler:nil];
    [alert addAction:action1];
    [alert addAction:action2];
    
    [self presentViewController:alert animated:YES completion:nil];
}

- (void)itemAction:(UIBarButtonItem *)item {
    LandViewController *landVC = [[LandViewController alloc] init];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:landVC];
    self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentViewController:nav animated:YES completion:^{
        
    }];
    
    landVC.block = ^(NSString *str) {
        UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithTitle:str style:UIBarButtonItemStylePlain target:self action:@selector(item2Action:)];
        self.navigationItem.rightBarButtonItem = item2;
    };

    
    [landVC release];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];

    if (indexPath.row == 0) {
        cell.textLabel.text = @"我的活动";
    }
    else if (indexPath.row == 1) {
        cell.textLabel.text = @"我的电影";
    }
    else if (indexPath.row == 2) {
        cell.textLabel.text = @"清除缓存";
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    ActivityCllectViewController *acCVC = [[ActivityCllectViewController alloc] init];
    MovieCllectViewController *moCVC = [[MovieCllectViewController alloc] init];
    if (indexPath.row == 0) {
        [self.navigationController pushViewController:acCVC animated:YES];

//        NSLog(@"sec------%@", seVC.arr);
        acCVC.accArr = [[MyDataBaseHandle sharedDataBaseHandle] selectTable];
        
    } else if (indexPath.row == 1) {
        [self.navigationController pushViewController: moCVC animated:YES];
        moCVC.moviArr = [[MyDataBaseHandle sharedDataBaseHandle] selectTableMovie];
    } else if (indexPath.row == 2) {
        [[SDImageCache sharedImageCache] cleanDisk];
    }
    [acCVC release];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
